<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>A2P</title>

        <script src="../js/jquery.functions.js" type="text/javascript"></script>


        <style type="text/css" title="currentStyle">
            @import "../tabla/demo_page.css";
            @import "../tabla/demo_table.css";
        </style>

        <script type="text/javascript" language="javascript" src="../tabla/jquery.dataTables.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#example').dataTable();
            } );
			
            function exportar(){
                document.getElementById('excel').src="exportarexcel.php"
            }
        </script>
    </head>

    <body id="dt_example">



        <div id="container" style="width:700px">


            <div id="demo">


                <table id="example" class="display">
                    <thead>
                        <tr>
                            <th>Cliente</th>
                            <th>Telefono</th>
                            <th>Cantidad</th>


                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if(strtotime($fecha_fin)<strtotime($fecha_ini)){
                            $aux=$fecha_fin;
                            $fecha_fin=$fecha_ini;
                            $fecha_ini=$aux;
                        }
                        
                        
                        $link = mysql_connect("localhost", "admin", "Xurpas123");
                        mysql_select_db("smsnic", $link);
                        
                        
                        $sql = "SELECT cl.`nombres` , t.`telefono` , COUNT(*) AS cantidad
                                FROM  `envios` e
                                INNER JOIN  `mensajes` m ON ( e.`id_mensaje` = m.`id` ) 
                                INNER JOIN  `telefonos` t ON ( e.`id_telefono` = t.`id` ) 
                                INNER JOIN cliente cl ON ( t.`telefono` LIKE CONCAT(  '505', cl.`telefono` ) ) 
                                INNER JOIN  `operadora` o ON ( t.`operadora_id` = o.`id` ) 
                                INNER JOIN estado esta ON ( e.`estado` = esta.`id` ) 
                                WHERE e.`estado`=1 and e.`fecha` BETWEEN '" . $fecha_ini . "' AND '" . $fecha_fin . "'
                                GROUP BY t.`telefono`
                                ORDER BY cantidad DESC
                                LIMIT 10
                        ";
                        $result1 = mysql_query($sql, $link) or die(mysql_error());

                        if (mysql_num_rows($result1)) {
                            while ($cliente = @mysql_fetch_array($result1)) {
                                ?>

                                <tr class="gradeA">
                                    <td class="center"><?php echo $cliente['nombres'] ?></td>
                                    <td class="center"><?php echo $cliente['telefono'] ?></td>
                                    <td class="center"><?php echo $cliente['cantidad'] ?></td>



                                </tr>
                                <?php
                            }
                        }
                        ?>
                    </tbody>
                    <tfoot>

                        <tr>
                            <th>Cliente</th>
                            <th>Telefono</th>
                            <th>Cantidad</th>

                        </tr>

                    </tfoot>
                </table>   
            </div>
            <table>
                <tr>
                    <td align="center">



                    </td>
                </tr>
            </table>
            <div class="spacer"></div>



        </div>

        <iframe style="display:none" id="excel">
        </iframe>

    </body>

</html>



